package com.cn.jinl.service;


import com.cn.jinl.api.IAbandonMaterialService;
import com.cn.jinl.dao.AbandonMaterialMapper;
import com.cn.jinl.domain.AbandonMaterial;
import com.cn.jinl.domain.AbandonMaterialExample;
import com.cn.jinl.domain.GongxuVo;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.Constants;
import com.cn.jinl.utils.QueryForm;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AbandonMaterialServiceImpl implements IAbandonMaterialService {

    @Autowired
    private AbandonMaterialMapper abandonMaterialMapper;

    @Override
    public List<AbandonMaterial> getAbandonMaterialList(QueryForm queryForm) throws Exception {
        int count = abandonMaterialMapper.selectAbandonMaterialListCount(queryForm);
        if(count == 0){
            return Lists.newArrayList();
        }
        List<AbandonMaterial> abandonMaterials = abandonMaterialMapper.selectAbandonMaterialList(queryForm);
        abandonMaterials.get(0).setCount(count);
        return abandonMaterials;
    }

    @Override
    public List<AbandonMaterial> getAPIAbandonMaterialList() throws Exception {
        Date now = new Date();
        long nowDay = now.getTime();
        long threeDay = nowDay - 1000L*60L*60L*24*3L;
        AbandonMaterialExample example = new AbandonMaterialExample();
        example.createCriteria().andStatusEqualTo(Constants.NORMAL_STATUS).andCreateTimeBetween(new Date(threeDay),now);
        example.setOrderByClause("create_time desc");
        List<AbandonMaterial> abandonMaterials = abandonMaterialMapper.selectByExample(example);
        return abandonMaterials;
    }

    @Override
    public String addAbandonMaterial(AbandonMaterial abandonMaterial) throws Exception {
        String id = CommonUtil.generateRandomNum("abandon-");
        abandonMaterial.setId(id);
        int count = abandonMaterialMapper.insertSelective(abandonMaterial);
        return CommonUtil.outStr(count);
    }

    @Override
    public List<GongxuVo> getGongXuList() throws Exception {
        List<GongxuVo> gongxuVos = Lists.newArrayList();
        GongxuVo gongxuVo1 = new GongxuVo();
        gongxuVo1.setName("配拌投料");

        List<GongxuVo> gongxuVo1s = Lists.newArrayList();
        GongxuVo gongxuVo11 = new GongxuVo();
        gongxuVo11.setName("U直");

        GongxuVo gongxuVo12 = new GongxuVo();
        gongxuVo12.setName("伸直");

        GongxuVo gongxuVo13 = new GongxuVo();
        gongxuVo13.setName("普直");

        GongxuVo gongxuVo14 = new GongxuVo();
        gongxuVo14.setName("通用");
        gongxuVo1s.add(gongxuVo11);
        gongxuVo1s.add(gongxuVo12);
        gongxuVo1s.add(gongxuVo13);
        gongxuVo1s.add(gongxuVo14);
        gongxuVo1.setChildren(gongxuVo1s);

        GongxuVo gongxuVo2 = new GongxuVo();
        List<GongxuVo> gongxuVo2s = Lists.newArrayList();
        gongxuVo2.setName("挤塑直切");
        GongxuVo gongxuVo21 = new GongxuVo();
        gongxuVo21.setName("U直");
        GongxuVo gongxuVo22 = new GongxuVo();
        gongxuVo22.setName("伸直");
        GongxuVo gongxuVo23 = new GongxuVo();
        gongxuVo23.setName("普直");
        gongxuVo2s.add(gongxuVo21);
        gongxuVo2s.add(gongxuVo22);
        gongxuVo2s.add(gongxuVo23);
        gongxuVo2.setChildren(gongxuVo2s);

        GongxuVo gongxuVo3 = new GongxuVo();
        List<GongxuVo> gongxuVo3s = Lists.newArrayList();
        gongxuVo3.setName("成型");
        GongxuVo gongxuVo31 = new GongxuVo();
        gongxuVo31.setName("U管成型");
        gongxuVo3s.add(gongxuVo31);
        gongxuVo3.setChildren(gongxuVo3s);

        GongxuVo gongxuVo4 = new GongxuVo();
        List<GongxuVo> gongxuVo4s = Lists.newArrayList();
        gongxuVo4.setName("包装");
        GongxuVo gongxuVo41 = new GongxuVo();
        gongxuVo41.setName("单支联排");
        GongxuVo gongxuVo42 = new GongxuVo();
        gongxuVo42.setName("多支");
        GongxuVo gongxuVo43 = new GongxuVo();
        gongxuVo43.setName("伸缩");
        GongxuVo gongxuVo44 = new GongxuVo();
        gongxuVo44.setName("U型");
        gongxuVo4s.add(gongxuVo41);
        gongxuVo4s.add(gongxuVo42);
        gongxuVo4s.add(gongxuVo43);
        gongxuVo4s.add(gongxuVo44);
        gongxuVo4.setChildren(gongxuVo4s);
        gongxuVos.add(gongxuVo1);
        gongxuVos.add(gongxuVo2);
        gongxuVos.add(gongxuVo3);
        gongxuVos.add(gongxuVo4);
        return gongxuVos;
    }
}
